package com.fyw.kotlin.base

import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import com.tonbu.ghproject.widget.LoadingDialog


/**
 * Created by FYW on 2017/9/28.
 */
abstract class BaseActivity : AppCompatActivity() {
    lateinit var loadingDialog:LoadingDialog                                                        //App加载等待对话框

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val bundle = intent.extras
        initParam(bundle)

        val view = LayoutInflater.from(this).inflate(bindLayout(), null)
        setContentView(view)

        loadingDialog =LoadingDialog(this)

        initView(view)

        doBusiness(this)
    }

    /**
     * 初始化参数
     */
    abstract fun initParam(param: Bundle?)

    /**
     * 绑定布局
     */
    abstract fun bindLayout(): Int

    /**
     * 初始化控件
     */
    abstract fun initView(view: View)

    /**
     * 业务操作
     */
    abstract fun doBusiness(mContext: Context)

    /**
     * 简化Toast
     *
     * @param msg
     */
    fun showToast(msg: String) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
    }
}